/** * Implements the [story:] autotag. * * @param string $op operation to perform * @param string $content item (e.g. story text), including the autotag * @param array $autotag parameters used in the autotag * @param mixed tag names (for $op='tagname') or formatted content */ function plugin_autotags_story($op, $content = '', $autotag = '') { global $_CONF, $_TABLES, $LANG24, $_GROUPS; if ($op == 'tagname') { return 'story'; } elseif ($op == 'permission' || $op == 'nopermission') { $flag = $op == 'permission'; $tagnames = array(); if (isset($_GROUPS['Story Admin'])) { $group_id = $_GROUPS['Story Admin']; } else { $group_id = DB_getItem($_TABLES['groups'], 'grp_id', "grp_name = 'Story Admin'"); } $owner_id = SEC_getDefaultRootUser(); $p = 'autotag_permissions_story'; if (COM_getPermTag($owner_id, $group_id, $_CONF[$p][0], $_CONF[$p][1], $_CONF[$p][2], $_CONF[$p][3]) == $flag) { $tagnames[] = 'story'; } if (count($tagnames) > 0) { return $tagnames; } } elseif ($op == 'description') { return array('story' => $LANG24['autotag_desc_story']); } else { $sid = COM_applyFilter($autotag['parm1']); $sid = COM_switchLanguageIdForObject($sid); if (!empty($sid)) { $result = DB_query("SELECT COUNT(*) AS count " . "FROM {$_TABLES['stories']} " . "WHERE sid = '{$sid}'"); $A = DB_fetchArray($result); if ($A['count'] > 0) { $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $sid); $linktext = $autotag['parm2']; if (empty($linktext)) { $linktext = stripslashes(DB_getItem($_TABLES['stories'], 'title', "sid = '{$sid}'")); } $link = COM_createLink($linktext, $url); $content = str_replace($autotag['tagstr'], $link, $content); } } return $content; } }
/** * Implements the [topic:] autotag. * * @param string $op operation to perform * @param string $content item (e.g. topic text), including the autotag * @param array $autotag parameters used in the autotag * @param mixed tag names (for $op='tagname') or formatted content * */ function plugin_autotags_topic($op, $content = '', $autotag = '') { global $_CONF, $_TABLES, $LANG27, $_GROUPS; if ($op == 'tagname') { return array('topic', 'related_topics', 'related_items'); } elseif ($op == 'permission' || $op == 'nopermission') { if ($op == 'permission') { $flag = true; } else { $flag = false; } $tagnames = array(); if (isset($_GROUPS['Topic Admin'])) { $group_id = $_GROUPS['Topic Admin']; } else { $group_id = DB_getItem($_TABLES['groups'], 'grp_id', "grp_name = 'Topic Admin'"); } $owner_id = SEC_getDefaultRootUser(); if (COM_getPermTag($owner_id, $group_id, $_CONF['autotag_permissions_topic'][0], $_CONF['autotag_permissions_topic'][1], $_CONF['autotag_permissions_topic'][2], $_CONF['autotag_permissions_topic'][3]) == $flag) { $tagnames[] = 'topic'; } if (COM_getPermTag($owner_id, $group_id, $_CONF['autotag_permissions_related_topics'][0], $_CONF['autotag_permissions_related_topics'][1], $_CONF['autotag_permissions_related_topics'][2], $_CONF['autotag_permissions_related_topics'][3]) == $flag) { $tagnames[] = 'related_topics'; } if (COM_getPermTag($owner_id, $group_id, $_CONF['autotag_permissions_related_items'][0], $_CONF['autotag_permissions_related_items'][1], $_CONF['autotag_permissions_related_items'][2], $_CONF['autotag_permissions_related_items'][3]) == $flag) { $tagnames[] = 'related_items'; } if (count($tagnames) > 0) { return $tagnames; } } elseif ($op == 'description') { return array('topic' => $LANG27['autotag_desc_topic'], 'related_topics' => $LANG27['autotag_desc_related_topics'], 'related_items' => $LANG27['autotag_desc_related_items']); } elseif ($op == 'parse') { if ($autotag['tag'] != 'topic' && $autotag['tag'] != 'related_topics' && $autotag['tag'] != 'related_items') { return $content; } if ($autotag['tag'] == 'topic') { $tid = COM_applyFilter($autotag['parm1']); if (!empty($tid) && SEC_hasTopicAccess($tid) > 0) { $tid = DB_escapeString($tid); $sql = "SELECT COUNT(*) AS count FROM {$_TABLES['topics']} WHERE tid = '{$tid}'"; $result = DB_query($sql); $A = DB_fetchArray($result); if ($A['count'] == 1) { $url = COM_buildUrl($_CONF['site_url'] . '/index.php?topic=' . $tid); $linktext = $autotag['parm2']; if (empty($linktext)) { $linktext = stripslashes(DB_getItem($_TABLES['topics'], 'topic', "tid = '{$tid}'")); } $link = COM_createLink($linktext, $url); $content = str_replace($autotag['tagstr'], $link, $content); } } } elseif ($autotag['tag'] == 'related_topics') { $id = COM_applyFilter($autotag['parm1']); $type = ''; $max = $_CONF['related_topics_max']; // Article Default $tids = array(); $skip = 0; $px = explode(' ', trim($autotag['parm2'])); if (is_array($px)) { foreach ($px as $part) { if (substr($part, 0, 5) == 'type:') { $a = explode(':', $part); $type = $a[1]; $skip++; } elseif (substr($part, 0, 4) == 'max:') { $a = explode(':', $part); $max = $a[1]; $skip++; } elseif (substr($part, 0, 6) == 'topic:') { $a = explode(':', $part); $tids[] = $a[1]; // Add each topic when found $skip++; } else { break; } } } $related_topics = ''; if (!empty($type) and !empty($id)) { // Return topics of object $related_topics = TOPIC_relatedTopics($type, $id, $max); } elseif (!empty($tids)) { // Since list of topics specified add id to topic list (since really a topic) if (!empty($id)) { $tids[] = $id; } $related_topics = TOPIC_relatedTopics('', '', $max, $tids); } if (!empty($related_topics)) { $content = str_replace($autotag['tagstr'], $related_topics, $content); } } elseif ($autotag['tag'] == 'related_items') { $id = COM_applyFilter($autotag['parm1']); $type = ''; $max = $_CONF['related_topics_max']; // Article Default $trim = 0; $include_types = array(); $tids = array(); $skip = 0; $px = explode(' ', trim($autotag['parm2'])); if (is_array($px)) { foreach ($px as $part) { if (substr($part, 0, 5) == 'type:') { $a = explode(':', $part); $type = $a[1]; $skip++; } elseif (substr($part, 0, 4) == 'max:') { $a = explode(':', $part); $max = $a[1]; $skip++; } elseif (substr($part, 0, 5) == 'trim:') { $a = explode(':', $part); $trim = $a[1]; $skip++; } elseif (substr($part, 0, 6) == 'topic:') { $a = explode(':', $part); $tids[] = $a[1]; // Add each topic when found $skip++; } elseif (substr($part, 0, 8) == 'include:') { $a = explode(':', $part); $include_types[] = $a[1]; // Add each type when found $skip++; } else { break; } } } $related_items = ''; if (!empty($type) and !empty($id)) { // Return topics of object $related_items = TOPIC_relatedItems($type, $id, $include_types, $max, $trim, $tids); } elseif (!empty($tids) or !empty($id)) { // Since list of topics specified add id to topic list (since really a topic) $tids[] = $id; $related_items = TOPIC_relatedItems('', '', $include_types, $max, $trim, $tids); } if (!empty($related_items)) { $content = str_replace($autotag['tagstr'], $related_items, $content); } } return $content; } }
/** * Implements the [block:] autotag. * * @param string $op operation to perform * @param string $content item (e.g. block text), including the autotag * @param array $autotag parameters used in the autotag * @param mixed tag names (for $op='tagname') or formatted content * */ function plugin_autotags_block($op, $content = '', $autotag = '') { global $_CONF, $_TABLES, $LANG21, $_GROUPS; if ($op == 'tagname') { return array('block'); } elseif ($op == 'permission' || $op == 'nopermission') { if ($op == 'permission') { $flag = true; } else { $flag = false; } $tagnames = array(); if (isset($_GROUPS['Block Admin'])) { $group_id = $_GROUPS['Block Admin']; } else { $group_id = DB_getItem($_TABLES['groups'], 'grp_id', "grp_name = 'Block Admin'"); } $owner_id = SEC_getDefaultRootUser(); if (COM_getPermTag($owner_id, $group_id, $_CONF['autotag_permissions_block'][0], $_CONF['autotag_permissions_block'][1], $_CONF['autotag_permissions_block'][2], $_CONF['autotag_permissions_block'][3]) == $flag) { $tagnames[] = 'block'; } if (count($tagnames) > 0) { return $tagnames; } } elseif ($op == 'description') { return array('block' => $LANG21['autotag_desc_block']); } elseif ($op == 'parse') { $name = COM_applyFilter($autotag['parm1']); if (!empty($name)) { $result = DB_query("SELECT * " . "FROM {$_TABLES['blocks']} " . "WHERE name = '{$name}' AND is_enabled = 1"); $A = DB_fetchArray($result); if (DB_numRows($result) > 0) { switch ($autotag['tag']) { case 'block': $px = explode(' ', trim($autotag['parm2'])); $css_class = "block-autotag"; $css_style = ""; if (is_array($px)) { foreach ($px as $part) { if (substr($part, 0, 6) == 'class:') { $a = explode(':', $part); // append a class $css_class .= ' ' . $a[1]; } elseif (substr($part, 0, 6) == 'width:') { $a = explode(':', $part); // add width style $css_style = ' style="width:' . $a[1] . '"'; } else { break; } } } $retval = COM_formatBlock($A, false, true); // COM_formatBlock could return '' if wrong device, etc... if ($retval != '') { // the class block-autotag will always be included with the div $retval = '<div class="' . $css_class . '"' . $css_style . '>' . $retval . '</div>'; } break; } $content = str_replace($autotag['tagstr'], $retval, $content); } } } return $content; }
/** * Implements the [user:] autotag. * * @param string $op operation to perform * @param string $content item (e.g. story text), including the autotag * @param array $autotag parameters used in the autotag * @return mixed tag names (for $op='tagname') or formatted content */ function plugin_autotags_user($op, $content = '', $autotag = array()) { global $_CONF, $_TABLES, $LANG28, $_GROUPS; if ($op === 'tagname') { return 'user'; } elseif ($op === 'permission' || $op === 'nopermission') { if ($op === 'permission') { $flag = true; } else { $flag = false; } $tagNames = array(); if (isset($_GROUPS['User Admin'])) { $group_id = $_GROUPS['User Admin']; } else { $group_id = DB_getItem($_TABLES['groups'], 'grp_id', "grp_name = 'User Admin'"); } $owner_id = SEC_getDefaultRootUser(); if (COM_getPermTag($owner_id, $group_id, $_CONF['autotag_permissions_user'][0], $_CONF['autotag_permissions_user'][1], $_CONF['autotag_permissions_user'][2], $_CONF['autotag_permissions_user'][3]) == $flag) { $tagNames[] = 'user'; } if (count($tagNames) > 0) { return $tagNames; } } elseif ($op === 'description') { return array('user' => $LANG28['autotag_desc_user']); } elseif ($op === 'parse') { $uName = COM_applyFilter($autotag['parm1']); $uName = DB_escapeString($uName); $sql = "SELECT uid, username, fullname, status FROM {$_TABLES['users']} WHERE username = '******'"; $result = DB_query($sql); if (DB_numRows($result) == 1) { $A = DB_fetchArray($result); $url = $_CONF['site_url'] . '/users.php?mode=profile&uid=' . $A['uid']; $linkText = $autotag['parm2']; if (empty($linkText)) { $linkText = COM_getDisplayName($A['uid'], $A['username'], $A['fullname']); if ($A['status'] == USER_ACCOUNT_DISABLED) { $linkText = sprintf('<s title="%s">%s</s>', $LANG28[42], $linkText); } } $link = COM_createLink($linkText, $url); $content = str_replace($autotag['tagstr'], $link, $content); } return $content; } }