define('JOOM_HTTP', 'http://site.ru');
define('JOOM_ADM_PASS', 'admin');
define('JOOM_ADM_LOGIN', 'admin');
//*******************************
class JGPoster { // Joom Gallery Poster
private static function defOptions() {
$options = Array();
return $options;
} // end of function
public static function doAuth() {
$ret = false;
$options = self::defOptions();
$options['url'] = JOOM_HTTP.'/administrator/index.php';
$result = SP::Get($options);
if (!emptyempty($result['return']['data'])) {
$html = $result['return']['data'];
if (strpos($html, 'task=logout')) {
$ret = true;
} else {
$options = self::defOptions();
$options['url'] = JOOM_HTTP.'/administrator/index.php';
$options['post'] = Array();
$options['post']['lang'] = '';
$options['post']['option'] = 'com_login';
$options['post']['username'] = JOOM_ADM_LOGIN;
$options['post']['passwd'] = JOOM_ADM_PASS;
$options['post']['task'] = 'login';
if (preg_match('|<input\s+type="hidden"\s+name="([a-z0-9]{32})"\s+value="([^"]+)"|Usix', $html, $regs)) {
$options['post'][$regs[1]] = $regs[2];
}
$result = SP::Get($options);
if (!emptyempty($result['return']['data'])) {
$html = $result['return']['data'];
if (strpos($html, 'task=logout')) $ret = true;
}
}
}
return $ret;
} // end of function
public static function getJGCatList($likeSelect=true, $name='f_cat', $selectMax=true) {
$ret = false;
$options = self::defOptions();
$options['url'] = JOOM_HTTP.'/administrator/index.php?option=com_joomgallery&controller=upload';
$result = SP::Get($options);
if (!emptyempty($result['return']['data'])) {
$html = $result['return']['data'];
if (preg_match('|<select\s+name="catid".+/select|Usix', $html, $regs)) {
if (preg_match_all('|<option\svalue="(\d+)">([^<]+)</option>|Usix', $regs[0], $regs)) {
$ret = Array();
for ($i=0; $i<count($regs[0]); $i++) $ret[$regs[1][$i]] = trim($regs[2][$i]);
if ($ret && $likeSelect) {
$oret = '<select name="'.$name.'">';
$max=0;
if ($selectMax) foreach ($ret as $k=>$r) if ($k>$max) $max=$k;
foreach ($ret as $k=>$r) {
$oret.='<option value="'.$k.'"';
if ($selectMax && ($max==$k)) $oret.=' selected="selected"';
$oret.='>'.$r.'</option>';
}
$ret = $oret.'</select>';
}
}
}
}
return $ret;
} // end of function
public static function addCategory($catName, $parentid=0) {
$ret = false;
$options = self::defOptions();
$options['url'] = JOOM_HTTP.'/administrator/index.php';
$options['post'] = Array();
$options['post']['alias'] ='';
$options['post']['cid'] ='0';
$options['post']['controller'] ='categories';
$options['post']['description'] ='';
$options['post']['details[access]'] ='0';
$options['post']['details[catimage]'] ='';
$options['post']['details[img_position]'] ='0';
$options['post']['details[owner]'] ='0';
$options['post']['meta[metadesc]'] ='';
$options['post']['meta[metakey]'] ='';
$options['post']['name'] =$catName;
$options['post']['option'] ='com_joomgallery';
$options['post']['ordering'] ='0';
$options['post']['parent'] =$parentid;
$options['post']['published'] ='1';
$options['post']['task'] ='apply';
$result = SP::Get($options);
if (!emptyempty($result['return']['data'])) {
$html = $result['return']['data'];
if (preg_match('|<strong>ID\sкатегории</strong>.{0,20}</td>.{0,20}<td>\D*(\d+)\D*</td>|Usix', $html, $regs))
$ret=$regs[1];
}
return $ret;
} // end of function
public static function postImage($catid, $imagepath, $title = 'Image', $desc='') {
$ret = false;
$options = self::defOptions();
$options['url'] = JOOM_HTTP.'/administrator/index.php';
$options['post'] = Array();
$options['post']['catid'] = $catid;
$options['post']['gentitle'] = $title;
$options['post']['gendesc'] = $desc;
$options['post']['photocred'] = '';
$options['post']['option'] = 'com_joomgallery';
$options['post']['controller'] = 'upload';
$options['post']['task'] = 'upload';
for ($i=1; $i<10; $i++) $options['post']['arrscreenshot['.$i.']']='';
$options['post']['arrscreenshot[0]']='@'.$imagepath;
$result = SP::Get($options);
if (!emptyempty($result['return']['data'])) {
$html = $result['return']['data'];
if (preg_match('|<dl\sid="system-message">.+</dl>|Usix', $html, $regs)) {
if (preg_match_all('|<li>(.+)</li>|Usix', $regs[0], $regs)) {
$ret = Array();
for($i=0; $i<count($regs[0]); $i++) $ret[] = trim($regs[1][$i]);
}
}
}
return $ret;
} // end of function
} // end of class
Leave a Reply